package schoolWork.work05.test4;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyJFrame extends JFrame implements ActionListener {
    int number;
    String translate;
    public MyJFrame(){
        initJFrame();
    }

    public void initJFrame(){
        // 创建一个文本框
        JTextField jTextField = new JTextField(10);
        jTextField.addActionListener(this);
        // 创建一个标签
        JLabel jLabel = new JLabel();
        jLabel.setText(translate+"");

        setLayout(new FlowLayout());
        add(jTextField);
        add(jLabel);

        setSize(300,300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        number = Integer.parseInt(e.getActionCommand());
        switch (number){
            case 0:
                translate = "zero";
                break;
            case 1:
                translate = "one";
                break;
            case 2:
                translate = "two";
                break;
            case 3:
                translate = "three";
                break;
            case 4:
                translate = "four";
                break;
            case 5:
                translate = "five";
                break;
            case 6:
                translate = "six";
                break;
            case 7:
                translate = "seven";
                break;
            case 8:
                translate = "eight";
                break;
            case 9:
                translate = "nine";
                break;
            default:
                translate = "输入错误";
                break;
        }

        initJFrame();
    }
}
